import cn.yunhe.entity.Account;
import cn.yunhe.entity.Record;
import cn.yunhe.services.IAccountService;
import cn.yunhe.services.IRecordService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class Demo2 {
    ApplicationContext ac = null;
    IAccountService iAccountService = null;
    IRecordService iRecordService = null;
    Account account = new Account();
    Record record = new Record();

    @Before
    public void bef() {
        ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        iAccountService = (IAccountService) ac.getBean("accountService");
        iRecordService = (IRecordService) ac.getBean("recordService");
    }

    @Test
    public void addA() {
        account.setUname("白");
        account.setMoney(9999.9);
        account.setCreateDate("19/5/28");
        iAccountService.addAccount(account);
    }

    @Test
    public void upA() {
        account.setAid(1);
        account.setUname("凡");
        account.setMoney(0.9999);
        iAccountService.updateAccount(account);
    }

    @Test
    public void delA() {
        iAccountService.delAccount(1);
    }

    @Test
    public void searchA() {
        List<Account> list = iAccountService.searchAll("from Account");
        for (Account a : list) {
            System.out.println(a.getUname());
        }
    }

    @Test
    public void addR() {
        record.setFromAccount(92928);
        record.setToAccount(56967);
        record.setRecordTime("19/5/28");
        record.setRemark("转着玩");
        iRecordService.addRecord(record);
    }

    @Test
    public void searchR(){
        record=iRecordService.get(1);
        System.out.println(record);
    }
}
